import os

class ParsedURL(object):
    ''' This is used because urlparse returns a read-only tuple. '''
    def __init__(self, urlparseobj):
        if urlparseobj.scheme == '':
            self.scheme = 'file'
        else:
            self.scheme = urlparseobj.scheme

        self.netloc = urlparseobj.netloc
        self.path = urlparseobj.path
        self.query = urlparseobj.query
        self.fragment = urlparseobj.fragment
        self.username = urlparseobj.username
        self.password = urlparseobj.password
        self.hostname = urlparseobj.hostname
        self.port = urlparseobj.port

    def geturl(self):
        args = [self.scheme,'://']


        if not self.path.startswith('/'):
            args.append(os.getcwd())
            args.append('/')

        if self.username:
            args.append(self.username)

            if self.password:
                args.append(':')
                args.append(self.password)

            args.append('@')

        if self.hostname:
            args.append(self.hostname)

            if self.port:
                args.append(':')
                args.append(str(self.port))

        if self.path:
            args.append(self.path)

        if self.query:
            args.append("?")
            args.append(self.query)
        return ''.join(args)
